package cn.itzzx.lagou.mybatis.session;

import cn.itzzx.lagou.mybatis.config.XmlConfigBuilder;
import cn.itzzx.lagou.mybatis.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 *
 * 该类负责 调用 XmlConfigBuilder 对配置文件进行解析，并且封装成 Configuration 对象
 *
 * 将 Configuration 对象装载到需要返回的 SqlSessionFactory 当中
 *
 * @author Martin
 * @date 2020-04-25
 * @see 1.0
 */
public class SqlSessionFactoryBuilder {


    public SqlSessionFactory builder(InputStream inputStream) throws PropertyVetoException, DocumentException {
        // 通过 XmlConfigBuilder 对xml文件进行解析 返回Configuration
        XmlConfigBuilder xmlConfigBuilder = new XmlConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseXmlConfig(inputStream);
        // 构造 SqlSessionFactory
        return new DefaultSqlSessionFactory(configuration);
    }
}
